var DataDialog =
{
    //显示数据选择对话框
    Show: function (dialogCode, multiSelected, firstShow, where, fn) {
        if (multiSelected == undefined) multiSelected = false;
        if (firstShow == undefined) firstShow = true;

        var dialog = null;
        var url = serverUrl.webRoot + 'Tools/Dialog?dialogCode=' + dialogCode;
        url += '&multiSelected=' + multiSelected;
        url += '&firstShow=' + firstShow;
        if (where) url += '&where=' + where;
        url = encodeURI(url);
        var content = '<iframe src="' + url + '" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>';

        var div = document.createElement('div');
        $(div).window({
            title: '数据选择对话框',
            width: 500,
            height: 400,
            content: content,
            collapsible: false,
            minimizable: false,
            modal: true
        });
        $.post(serverUrl.webRoot + 'Dialog/GetDialog?dialogCode=' + dialogCode, function (data) {
            var json = parseJSON(data);
            if (json) {
                $(div).window('setTitle', json.Title + '-数据选择对话框');
                $(div).window('resize', { width: json.Width, height: json.Height });
                dialog = json;
            }
        });
        $(div).children('iframe')[0].OnSelected = function (value) {
            $(div).window('close');
            var ret = {};
            if (dialog.ResultFieldKey) {
                if (multiSelected == false) {
                    ret.result = value[0][dialog.ResultFieldKey];
                }
                else {
                    ret.result = '';
                    for (var i = 0; i < value.length; i++) {
                        ret.result += ',' + value[i][dialog.ResultFieldKey];
                    }
                    ret.result = ret.result.substr(1);
                }
            }
            if (multiSelected == false) {
                ret.data = value[0];
            }
            else {
                ret.data = value;
            }
            if (fn) fn(ret);
        };

        $(div).children('iframe')[0].Cancel = function () {
            $(div).window('close');
        }
    },
    //显示对话框并将选择的值返回到指定的输入框中
    ShowSingle: function (dialogCode, returnobj, firstShow, where) {
        this.Show(dialogCode, undefined, firstShow, where, function (value) {
            $(returnobj).val(value.result);
        });
    }

}